﻿using System;
using System.ComponentModel;
using System.Data.Linq.Mapping;

namespace Rachmans.Sabang.Model
{
    [Table]
    public class Bookmark : INotifyPropertyChanged, INotifyPropertyChanging
    {
        private int _page;

        [Column]
        public int Page {
            get
            {
                return _page;
            }
            set
            {
                if (_page != value)
                {
                    NotifyPropertyChanging("Page");
                    _page = value;
                    NotifyPropertyChanged("Page");
                }
            } 
        }

        private int _bookmarkId;

        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int BookmarkId {
            get
            {
                return _bookmarkId;
            }
            set
            {
                if (_bookmarkId != value)
                {
                    NotifyPropertyChanging("BookmarkId");
                    _bookmarkId = value;
                    NotifyPropertyChanged("BookmarkId");
                }
            }
        }

        private DateTime _dtmSave;

        [Column]
        public DateTime DtmSave
        {
            get
            {
                return _dtmSave;
            }
            set
            {
                if (_dtmSave != value)
                {
                    NotifyPropertyChanging("DtmSave");
                    _dtmSave = value;
                    NotifyPropertyChanged("DtmSave");
                }
            }
        }

        private void NotifyPropertyChanged(string p)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(p));
            }
        }

        private void NotifyPropertyChanging(string p)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(p));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public event PropertyChangingEventHandler PropertyChanging;
    }
}
